import configparser
import RPi.GPIO as GPIO


class rpi_GPIO():
    def __init__(self):
        config = configparser.ConfigParser()
        config.read("config_of_rpi.ini")

        self.LeftWheel = config.getint("wheels","LeftWheel")
        self.RightWheel = config.getint("wheels","RightWheel")
        
        GPIO.setmode(GPIO.BCM)

        GPIO.setup(self.LeftWheel,GPIO.OUT)
        GPIO.setup(self.RightWheel,GPIO.OUT)


        # other GPIO definition

    def reset(self):
        # reset: set all GPIO as LOW
        GPIO.output(self.LeftWheel.GPIO.LOW)
        GPIO.output(self.RightWheel.GPIO.LOW)

    def moveforward(self):
        # forward
        GPIO.output(self.LeftWheel.GPIO.HIGH)
        GPIO.output(self.RightWheel.GPIO.HIGH)

    def moveleft(self):
        # left
        GPIO.output(self.LeftWheel.GPIO.HIGH)
        GPIO.output(self.RightWheel.GPIO.HIGH)
        
    def moveright(self):
        # right
        GPIO.output(self.LeftWheel.GPIO.HIGH)
        GPIO.output(self.RightWheel.GPIO.HIGH)

    def movestop(self):
        # stop
        GPIO.output(self.LeftWheel.GPIO.HIGH)
        GPIO.output(self.RightWheel.GPIO.HIGH)

    def movejump(self):
        #jump
        print('jump')
    
    def charging(self):
        # battery charging
        print('charging')
    
    def discharging(self):
        # battery discharging
        print('discharging')


def IsCharge(rpi):
    # load ups data, judge the status of battery
    # 1 charging
    # 0 dis charging
    print('70')

    return 0

def main():
    # load and define GPIO of robot
    HellobotRpi = rpi_GPIO()
    print(HellobotRpi.LeftWheel)

    # input
    while(True):
        if IsCharge(HellobotRpi):
            HellobotRpi.charging

            while(True):
                if IsCharge(HellobotRpi):
                    continue
                else:
                    break
        
        order = input("An order:")
        HellobotRpi.movejump()

        if order == 'exit':
            break


if __name__ == '__main__':
    main()